home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 90 / CD Actual 90.iso / Software3D / K-3D / k3d-0.4.2.1 / shaders / k3d_oak.sl < prev    next >
Encoding:
Text File  |  2004-07-23  |  3.1 KB  |  84 lines

  1. /****************************************************************************
  2.  * oak.sl
  3.  *
  4.  * Description: makes procedural solid texture that looks very much like
  5.  *    wood grain.  The rings surround the z axis, so to position the
  6.  *    pattern, one should translate the shadingspace (which defaults to
  7.  *    "shader").  This makes a fairly plain, unfinished wood, that looks
  8.  *    very much like oak.
  9.  *   
  10.  * Parameters for the coordinate mapping: 
  11.  *   shadingspace - space in which the pattern is laid out
  12.  *   shadingfreq - overall scaling factor for the pattern
  13.  *   Pref - if supplied, gives the reference pose
  14.  *
  15.  * Parameters for the color and pattern: 
  16.  *   Clightwood - the light, "background" wood color
  17.  *   Cdarkwood - the darker color in the ring/grain
  18.  *   ringfreq - mean frequency of ring spacing
  19.  *   ringunevenness - 0=equally spaced rings, larger is unequally spaced
  20.  *   grainfreq - frequency of the fine grain
  21.  *   ringnoise, ringnoisefreq - general warping of the domain
  22.  *   trunkwobble, trunkwobblefreq - controls noise which wobbles the
  23.  *       axis of the trunk so that it's not perfectly on the z axis.
  24.  *   angularwobble, angularwobblefreq - warping indexed by angle about
  25.  *       the z axis.
  26.  *   ringy, grainy - overall scale on the degree to which rings and
  27.  *       grain are weighted.  0 turns one off, 1 makes full effect.
  28.  *   divotdepth - depth (in shader units) of the displacement due to
  29.  *       ring or grain.
  30.  *   truedisp - 1 for true displacement, 0 for bump mapping
  31.  *
  32.  * Parameters for illumination model:
  33.  *   Ka, Kd, Ks, roughness - the usual meaning
  34.  *   
  35.  ***************************************************************************
  36.  *
  37.  * Author: Larry Gritz, 1999
  38.  *
  39.  * Contacts:  lg@pixar.com
  40.  *
  41.  * $Revision: 1.1 $    $Date: 2002/11/25 20:24:00 $
  42.  *
  43.  ****************************************************************************/
  44.  
  45. #include "k3d_project.h"
  46. #include "k3d_pshad.h"
  47. #include "k3d_material.h"
  48. #include "k3d_displace.h"
  49.  
  50. #include "k3d_oak.h"
  51.  
  52.  
  53.  
  54. surface k3d_oak(float Ka = 1, Kd = 1, Ks = .25, roughness = 0.2;
  55.         DEFAULT_PSHAD_PARAMS;
  56.         float ringfreq = 8, ringunevenness = 0.5;
  57.         float ringnoise = 0.02, ringnoisefreq = 1;
  58.         float grainfreq = 25;
  59.         float trunkwobble = 0.15, trunkwobblefreq = 0.025;
  60.         float angularwobble = 1, angularwobblefreq = 1.5;
  61.         float divotdepth = 0.05;
  62.         color Clightwood = color(.5, .2, .067);    /* light wood color */
  63.         color Cdarkwood = color(0.15, 0.077, 0.028);
  64.         float ringy = 1, grainy = 1;
  65.         float truedisp = 0;
  66.   )
  67. {
  68.   GET_PSHAD;
  69.   normal Nf = faceforward(normalize(N), I);
  70.  
  71.   float wood;
  72.   wood =
  73.     oaktexture(Pshad, dPshad, ringfreq, ringunevenness, grainfreq, ringnoise,
  74.            ringnoisefreq, trunkwobble, trunkwobblefreq, angularwobble,
  75.            angularwobblefreq, ringy, grainy);
  76.   color Cwood = mix(Clightwood, Cdarkwood, wood);
  77.   Nf = faceforward(Displace(Nf, "shader", -wood * divotdepth, truedisp), I);
  78.  
  79.   /* Illumination model - just use plastic */
  80.   Ci = MaterialPlastic(Nf, Cwood, Ka, Kd, Ks * (1 - 0.5 * wood), roughness);
  81.   Oi = Os;
  82.   Ci *= Oi;
  83. }
  84.